package com.Service.Impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.Dao.BaseDaoI;
import com.Entity.Media;
import com.Entity.Mediacomment;
import com.Entity.Topiccomment;
import com.Service.MediaCommentService;

@Service("mediacommentservice")
public class MediaCommentServiceImpl extends BaseServiceImpl<Mediacomment> implements MediaCommentService  {

	@Autowired
	private BaseDaoI<Mediacomment> mediacommentdao;
	List<Mediacomment> mediacommentlist=new ArrayList<Mediacomment>();
	
	@Override
	public List<Mediacomment> findCommentByVideoId(long videoId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("videoId", videoId);
		
		String hql = "from Mediacomment t where t.videoId = :videoId";
		try {
			mediacommentlist=this.mediacommentdao.find(hql, params);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return mediacommentlist;
	}
	
	@Override
	public Long countTotalCommentByVideoId(long videoId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("videoId", videoId);
		String hql="select count(*) from Mediacomment t where t.videoId=:videoId";
		return mediacommentdao.count(hql, params);
	}
	
	@Override
	public List<Mediacomment> findCommentByVideoId(long videoId,int page,int rows) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("videoId", videoId);
		String hql="from Mediacomment t where t.videoId=:videoId order by commentTime ASC";
		return mediacommentdao.find(hql, params, page, rows);
	}
}
